package com.ww.grtsmanager.controller;

import com.ww.grtsmanager.bean.User;
import com.ww.grtsmanager.service.UserService;
import com.ww.grtsmanager.vo.EduResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public EduResult login(String userName, String passWord) {
        User user = userService.login(userName, passWord);
        return EduResult.ok(user);
    }

    @RequestMapping("/register")
    public EduResult register(@Valid @RequestBody User user){
        userService.register(user);
        return EduResult.ok();
    }
    @RequestMapping("/checked/{data}/{type}")
    public EduResult checked(@PathVariable String data,@PathVariable int type){
        userService.checked(data,type);
        return EduResult.ok();
    }
    @RequestMapping("/getCode/{email}")
    public EduResult getCode(@PathVariable String email){
        userService.generateCode(email);
        return EduResult.ok();
    }
    @RequestMapping("/changePassWord")
    public EduResult changePassWord(String email,Integer code,String passWord){
        userService.changePassWord(email,code,passWord);
        return EduResult.ok();
    }
}
